
<%@ page language="java" %>

<%@ page import="java.util.ArrayList,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.commons.Address,
                com.scalar.chiptrack.sales.SalesOrder,
                com.scalar.chiptrack.sales.dao.SalesOrderDAO,
                com.scalar.chiptrack.sales.LineItem,
                com.scalar.chiptrack.utils.ConfigManager, 
                com.scalar.chiptrack.operations.packingslip.actions.CommercialInvoiceAction,
                com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm,
                com.scalar.chiptrack.operations.packingslip.dao.CommercialInvoiceDAO"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML><HEAD><TITLE>ChipTrac - Commercial Invoice</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<style type="text/css">
a { text-decoration : none} 
</style>

<%
    String host = request.getHeader( "HOST" );
    int salesOrderId = -1;
    int customerShippingId = -1;
    boolean success = false;

    try {
        salesOrderId = Integer.parseInt (request.getParameter ("salesOrderId"));
        customerShippingId = Integer.parseInt (request.getParameter ("customerShippingId"));

        success = true;
    }
    catch (NumberFormatException nfe) {
        nfe.printStackTrace();
    }

    if (success == true) {

        Object[] result = CommercialInvoiceAction.getShippedLineItems (salesOrderId, customerShippingId);

        ArrayList lineItems = (ArrayList) result[0];
        request.setAttribute ("lineItems", lineItems);

        SalesOrder salesOrder = SalesOrderDAO.loadSalesOrder (salesOrderId+"");
        salesOrder.setSubTotal (Float.parseFloat((String) result[1]));
        request.setAttribute ("salesOrder", salesOrder);

        CommercialInvoiceForm cInvoiceForm = CommercialInvoiceDAO.loadCommercialInvoice( customerShippingId );
        cInvoiceForm.setSalesOrderId( salesOrderId );

        request.setAttribute( "commercialInvoiceForm", cInvoiceForm );
    }
%>

<LINK href="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<table align=center width='95%' border='0'>
    <tr>
        <td width="30%" align="center"><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/scalar_logo.jpg" height="120" width="200" border=0></td>
        <td width="40%" align=center><font class='NArialW'><u>Commercial Invoice</u></font><br></td>

        <td width="25%" align=center>
            <table width='50'align=center background='<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/printer_icon_small.gif'>
                <tr><td><a href="javascript:window.print();" title='Click here to print this Commercial Invoice'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                </td></tr>
            </table>
        </td>

        <td width="55%" align=center>&nbsp;</td>
    </tr>
</table>

<html:form name="commercialInvoiceForm" type="com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm" action="/commercialInvoice.do?action=save">
<html:hidden name="commercialInvoiceForm" property="customerShippingId"/>
<html:hidden name="commercialInvoiceForm" property="salesOrderId"/>
<html:hidden name='commercialInvoiceForm' property='packingSlipNumber'/>

<%
    SalesOrder salesOrder = (SalesOrder) request.getAttribute ("salesOrder");

    if( salesOrder != null ) 
    {
        Address billingAddress = salesOrder.getBillingAddressAsObject();
        Address shippingAddress = salesOrder.getShippingAddressAsObject();
%>

    <table width="95%" cellspacing='0' cellpadding='0' border=0 align=center>
    
        <tr><td colspan='5'><chiptrack:info styleClass='NArialL'/></td></tr>
        <tr><td colspan='5'><chiptrack:errors styleClass='NArialL'/></td></tr>
    
        <tr height=30>
            <td width="35%" class="NArialL" bgcolor="#DEE1E2" >&nbsp;Shipper :</td>
            <td colspan='3'><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width="35%"  bgcolor="#DEE1E2"><font class="NArialL">&nbsp;Consignee :</font></td>
        </tr>

        <tr>
            <td width="35%" bgcolor='#FFFFEE' class="NArialL">
                <table width='100%' class='NArialL'>
                    <nested:nest property='shipperAddress'>
                    <tr><td><%=ConfigManager.getClientAddressLine1()%> c/o <nested:write property='vendorName'/><br></td></tr>
                    <tr><td><nested:write property='address1'/></td></tr>
                    <tr><td><nested:write property='address2'/></td></tr>
                    <tr><td><nested:write property='city'/>, <nested:write property='state'/> - <nested:write property='zipCode'/></td></tr>
                    </nested:nest>
                </table>
            </td>
            <td colspan='3'><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif"></td>
            <td width='35%' bgcolor='#FFFFEE' class="NArialL">
                <%=salesOrder.getCustomerName()%>,<br>
                <%=( ( billingAddress.getAddress1() == null ) || ( billingAddress.getAddress1().trim().length() == 0 ) )? "" : billingAddress.getAddress1()+",<br>"%>
                <%=( ( billingAddress.getAddress2() == null ) || ( billingAddress.getAddress2().trim().length() == 0 ) ) ? "" : billingAddress.getAddress2()+",<br>"%>
                <%=( ( billingAddress.getCity() == null) || ( billingAddress.getCity().trim().length() == 0 ) ) ? "" : billingAddress.getCity()%>, <%=( ( billingAddress.getState() == null ) || ( billingAddress.getState().trim().length() == 0 ) ) ? "" : billingAddress.getState()%> <%=( ( billingAddress.getZipCode() == null) || ( billingAddress.getZipCode().trim().length() == 0 ) ) ? "" : "-" + billingAddress.getZipCode() + ".<br>"%>
            </td>
       </tr>
       <tr><td colspan=5><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

       <tr><td class="NArialL" colspan='5'>
            <table width='100%' border='0'>

                <tr>
                    <td width='20%' class='NArialL' align='left'>Sales Order#:</td>
                    <td width='25%'  class='NArialL' align='left'><%=salesOrder.getSalesOrderNo()%></td>
                    <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                    <td width='20%' class='NArialL' align='right'>Packing Slip#&nbsp;:</td>
                    <td width='25%'  class='NArialL' align='left'><bean:write name='commercialInvoiceForm' property='packingSlipNumber'/></td>
                </tr>

                <tr>
                    <td width='20%' class='NArialL' align='right'>&nbsp;</td>
                    <td width='25%'  class='NArialL' align='left'>&nbsp;</td>
                    <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                    <td width='20%' class='NArialL' align='right'>Customer P.O. #&nbsp;:</td>
                    <td width='25%'  class='NArialL' align='left'><%=( ( salesOrder.getCustomerPO() == null ) || ( salesOrder.getCustomerPO().trim().length() == 0 ) ) ? "&nbsp;" : salesOrder.getCustomerPO()%></td>
                </tr>

                <tr>
                    <td width='20%' class='NArialL' align='left'>INCOTERMS:</td>
                    <td width='25%'  class='NArialL' align='left'><%=( ( salesOrder.getDeliveryTerms() == null ) || ( salesOrder.getDeliveryTerms().trim().length() == 0 ) ) ? "&nbsp;" : salesOrder.getDeliveryTerms()%></td>
                    <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                    <td width='20%' class='NArialL' align='right'>Country of Origin&nbsp;:</td>
                    <td width='25%'  class='NArialL' align='left'><bean:write name='commercialInvoiceForm' property='countryOfOrigin' /></td>
                </tr>

                <tr>
                    <td width='20%' class='NArialL' align='left'>Loading Port:</td>
                    <td width='25%'  class='NArialL' align='left'><bean:write name='commercialInvoiceForm' property='portOfLanding' /></td>
                    <td width='10%' class='NArialL' align='right'>&nbsp;</td>
                    <td width='20%' class='NArialL' align='right'>Destination Port&nbsp;:</td>
                    <td width='25%'  class='NArialL' align='left'><bean:write name='commercialInvoiceForm' property='portOfDestination' /></td>
                </tr>
            </table>
        </td></tr>

       <tr><td colspan=5><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

       <tr><td colspan='5'>
       <table width="100%" border=1 cellpadding='0' cellspacing='0' bordercolor='#000000'>
            <tr height=30>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Line#</td>
                <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MFG_PARTNO_PACKINGSLIP ) ) { %>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>
				<bean:message key = "label.mfgPartNumber" /></td>
                <% } %>
                <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MRKT_PARTNO_PACKINGSLIP ) ) { %>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>
				<bean:message key = "label.mktgPartNumber" /></td>
                <% } %>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Product Description</td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Schedule<br> Number</td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Shipped Qty</td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Unit<br>Price</td>
                <td class="NArialL" bgcolor='#DEE1E2' align=center>Line<br>Total</td>
            </tr>

            <%
                ArrayList lineItemList = ( ArrayList ) request.getAttribute( "lineItems" );
                
                if( ( lineItemList != null ) && ( lineItemList.size() != 0 ) ) 
                {
                    int lineItemListSize = lineItemList.size();
                    LineItem lineItem = null;
            %>
                <input type='hidden' name='lineItemListSize' value='<%=lineItemListSize%>'/>
            <%
                    int lineItemNumber = -1;
                    String mktPartNumber = null;
                    String mfgPartNumber = null;
                    String description = null;
                    String scheduleNumber = null;
                    String qty = null;
                    String unitPrice = null;
                    String amount = null;

                    for( int i = ( lineItemListSize-1 ); i >= 0; i-- )
                    {
                        lineItem = ( LineItem ) lineItemList.get( i );

                        lineItemNumber = lineItem.getLineItemNo();
                        mktPartNumber  = lineItem.getMarketingPartNo();
                        mfgPartNumber  = lineItem.getManufacturingPartNo();
                        description    = lineItem.getDescription();
                        scheduleNumber = lineItem.getScheduleNumber();
                        qty            = lineItem.getQtyAsString();
                        amount         = lineItem.getAmountAsString();
                        unitPrice      = lineItem.getUnitPriceAsString();

            %>
                    <tr height=30>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap><%=lineItemNumber%></td>
                        <% if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MFG_PARTNO_PACKINGSLIP ) ) { %>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <%=( ( mfgPartNumber == null ) || ( mfgPartNumber.trim().length() == 0 ) ) ? "&nbsp;" : mfgPartNumber%>
                        </td>
                        <% } if (ConfigManager.getBooleanProperty(ConfigManager.SHOW_MRKT_PARTNO_PACKINGSLIP ) ) { %>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <%=( ( mktPartNumber == null ) || ( mktPartNumber.trim().length() == 0 ) ) ? "&nbsp;" : mktPartNumber%>
                        </td>
                        <% } %>
                        <td bgcolor='#FFFFEE' class="NArialL" align=center>
                            <%=( ( description == null ) || ( description.trim().length() == 0 ) ) ? "&nbsp;" : description%>
                        </td>

                        <td bgcolor='#FFFFEE' class="NArialL" align=center nowrap>
                            <%=( ( scheduleNumber == null ) || ( scheduleNumber.trim().length() == 0 ) ) ? "&nbsp;" : scheduleNumber%>
                        </td>

                        <td bgcolor='#FFFFEE' class="NArialL" align=right nowrap>
                            <%=( ( qty == null ) || ( qty.trim().length() == 0 ) ) ? "&nbsp;" : qty%>
                        </td>

                        <td bgcolor='#FFFFEE' class="NArialL" align=right nowrap>
                            <%=( ( unitPrice == null ) || ( unitPrice.trim().length() == 0 ) ) ? "&nbsp;" : unitPrice%>
                        </td>

                        <td bgcolor='#FFFFEE' class="NArialL" align=right nowrap>
                            <%=( ( amount == null ) || ( amount.trim().length() == 0 ) ) ? "&nbsp;" : amount%>
                        </td>

                    </tr>
            <%
                    }       // while (lineItems.hasNext()) ...
                }           // if ((lineItemList != null) ...
            %>
            
            <tr><td colspan='7' align=center ><font class='NArialS'><br>NOTE: THE VALUE SHOWN IS FOR CUSTOMS PURPOSE ONLY.</font></td></tr>

        </table>

       </td></tr>


        <tr><td colspan=5 bgcolor='#DEE1E2' align="right"><font class='NArialL'>
		<!-- code that was commented for removed since it was not required. vasanth 08/26/2003-->
        Grand Total: <%=StringUtils.formatAmount((salesOrder.getSubTotal()), "$###,###.##")%>
        </font></td></tR>

    <tr><td colspan=5><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

    <tr><td colspan=5>
        <table width='100%' border='0'>
            <tr>
                <td width='20%' class='NArialL' align='right'>TOTAL PKGS:</td>
                <td width='5%'  class='NArialL' align='center'><bean:write name='commercialInvoiceForm' property='totalPackages'/></td>
                <td width='50%' class='NArialL' align='right'>&nbsp;</td>
                <td width='20%' class='NArialL' align='right'>License Symbol:</td>
                <td width='5%'  class='NArialL' align='left'><bean:write name='commercialInvoiceForm' property='licenseSymbol' /></td>
            </tr>
            <tr>
                <td width='20%' class='NArialL' align='right'>
					<% if( ConfigManager.getShowPackageDimensionInPackingSlip() ) { %>
                    NET WEIGHT:
                    <% } else { %>
                    WEIGHT:
                    <% } %>
				</td>
                <td width='5%'  class='NArialL' align='center'><bean:write name='commercialInvoiceForm' property='totalWeight'/></td>
                <td width='50%' class='NArialL' align='right'>&nbsp;</td>
                <td width='20%' class='NArialL' align='right'>ECCN:</td>
                <td width='5%'  class='NArialL' align='left'><bean:write name='commercialInvoiceForm' property='eccn' /></td>
            </tr>
        </table>
    </td></tr>

    <tr><td colspan=5><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tR>

    <tr><td colspan=5>
        <table width='100%' cellpadding='0' cellspacing='0' border='1' bordercolor='#000000' class='NArialL'>
            <tr><td>
                These commodities, technology, or software were exported from the United States in accordance<br>
                with the Export Administration regulations. Diversion contrary to U.S. law is prohibited.
            </td></tr>
        </table>
    </td></tr>

    <tr><td colspan=5><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif" height=25></td></tR>

    <tr>
        <td colspan='5'>

            <table border='0' width='100%' class='NArialL'>
                <td width='15%' align=center>Signature:</td>
                <td width='50%' align=left ><hr></td>
                <td width='5%' align=center>&nbsp;</td>
                <td width='10%' align=right>Date:</td>
                <td width='20%' align=center><hr></td>
            </table>

        </td>
    </tr>

    <tr><td colspan=5><img src="<%="http://" + host + "/" + chipTracContext%>/jsp/includes/images/spacer.gif" height=25></td></tR>

    </table>



    <%
        }       // if (salesOrder != null)...
    %>



</html:form>

</body>
</html>